@extends('layout.ionic')

@section('content')
    @inject('LostPresenter', 'App\Presenter\LostPresenter')
<div id="app" class="weui-msg">
    <div class="weui-msg__icon-area">
        @if($lost->status == 1)
        <i class="weui-icon-success weui-icon_msg"></i>
        @else
        <i class="weui-icon-warn weui-icon_msg"></i>
        @endif
    </div>
    <div class="weui-msg__text-area">
        <h2 class="weui-msg__title">
            {{ $LostPresenter->getScanTitle($lost->status) }}
        </h2>
        <p class="weui-msg__desc">班级：{{ $lost->class }}</p>
        <p class="weui-msg__desc">姓名：{{ $lost->name }}</p>
        <p class="weui-msg__desc">学号：{{ $lost->number }}</p>
    </div>
    <div class="weui-msg__opr-area">
        <p class="weui-btn-area">
            @if($lost->status === 1 && Auth::guard('wechat')->user()->havePermission('lost_audit'))
                <a href="javascript:" class="weui-btn weui-btn_primary" v-on:click="release">发放失物</a>
            @endif

            <a href="javascript:" class="weui-btn weui-btn_default" v-on:click="close">关闭页面</a>
        </p>
    </div>
    <div class="weui-msg__extra-area">
        <div class="weui-footer">
            <p class="weui-footer__text">Copyright © {{ date('Y') }} 计算机协会</p>
        </div>
    </div>
</div>
@endsection

@section('js')
    @include('app.partial.confirm')
    @include('app.partial.alert')
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>

        wx.config(<?php echo $js->config(array('closeWindow'), false, true) ?>);

        var audit = new Vue({
            el: '#app',
            data:{

            },
            methods: {
                release: function(){
                    confirmComponent.showConfirm('发放失物', '请确保失物已归还至失主', function(){
                        this.$http.post('{{ route('lost.release') }}', {id: '{{ $lost->id }}'}).then(function(response){
                            loading.show = false;
                            window.location.href=window.location.href+"?token=" + 10000 * Math.random();
                        }, function(response){
                            alertComponent.showAlert('操作失败', '请稍后尝试');
                        });
                    }, '处理中');
                },
                close: function(){
                    wx.closeWindow();
                }
            }
        })
    </script>

@endsection